package com.lh1010.s3.builder;

import com.zielsmart.beetlsql.starter.codegen.BaseProject;
import com.zielsmart.beetlsql.starter.codegen.Entity;
import com.zielsmart.beetlsql.starter.codegen.SourceConfig;
import com.zielsmart.beetlsql.starter.codegen.builder.BaseTemplateSourceBuilder;
import org.beetl.core.Template;

import java.io.Writer;

public class SearchVoBuilder extends BaseTemplateSourceBuilder {

    public SearchVoBuilder() {
        super("vo");
    }
    @Override
    public void generate(BaseProject project, SourceConfig config, Entity entity) {
        Template template = this.getGroupTemplate("template").getTemplate("searchVo.btl");
        template.binding("attrs", entity.getList());
        template.binding("className", entity.getName());
        template.binding("table", entity.getTableName());
        template.binding("useLombok", true);
        template.binding("useOpenApi", true);
        template.binding("tableDesc", entity.getTableDesc().getRemark());
        if (!config.isIgnoreDbCatalog()) {
            template.binding("catalog", entity.getCatalog());
        }

        String schema = null;

        try {
            schema = config.getSqlManager().getDs().getMetaData().getSchema();
        } catch (Exception var7) {
        }

        template.binding("schema", schema);
        template.binding("package", project.getBasePackage(this.name) + this.getPackageExt(null));
        template.binding("imports", entity.getImportPackage());
        template.binding("comment", entity.getComment());
        Writer writer = project.getWriterByName(this.name, this.getFileExt(null) + entity.getName() + "PageSearchVo.java");
        template.renderTo(writer);
    }
}
